package com.corpgovernment.organization.mq;

import com.corpgovernment.common.mq.enums.MessageBizTypeEnum;
import com.corpgovernment.common.mq.producer.CommonMQProducer;
import com.corpgovernment.organization.Bo.SyncEmployeeInfoMQBo;
import com.ctrip.corp.obt.generic.utils.JsonUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.common.message.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class SyncEmployeeInfoMQProducer {

    @Autowired
    private CommonMQProducer commonMQProducer;

    public boolean sendSyncEmployeeInfo(SyncEmployeeInfoMQBo syncEmployeeInfoMQBo) {
        try {
            Message message = new Message();
            message.setTopic(MessageBizTypeEnum.SYNC_EMPLOYEE_INFO.getTopic());
            message.setBody(JsonUtils.toJsonString(syncEmployeeInfoMQBo).getBytes());
            message.setTags(MessageBizTypeEnum.SYNC_EMPLOYEE_INFO.getTags());
            SendResult result = commonMQProducer.send(message);
            if (result != null && result.getSendStatus() == SendStatus.SEND_OK) {
                log.info("发送人员同步推送,入参:{}", JsonUtils.toJsonString(syncEmployeeInfoMQBo));
                return true;
            }
        } catch (Exception e) {
            log.error("发送人员同步推送失败", e);
        }
        return false;
    }
}
